/**
 * 
 */
package com.etc.controller.module;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.common.util.StringUtil;
import com.etc.module.service.IModuleService;
import com.etc.module.vo.CheckTreeNode;
import com.etc.module.vo.ModuleVO;
import com.etc.module.vo.TreeNode;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/menu")
public class ModuleController {
	
	@Autowired
	private IModuleService moduleService;
	

	@RequestMapping(value="/{id}.json",method=RequestMethod.GET)
	@ResponseBody
	public List<ModuleVO> getMenus(@PathVariable int id){
		List<ModuleVO> list=moduleService.findChildModuleByParentId(id);
		return list;
	}
	
	@RequestMapping(value="/tree/{id}",method=RequestMethod.GET)
	@ResponseBody
	public TreeNode findByParentId(@PathVariable int id){
		TreeNode treeNode=moduleService.findTreeMenu(id);
		return treeNode;
 	}
	
	@RequestMapping(value="/oper/{id}",method=RequestMethod.GET)
    @ResponseBody
    public CheckTreeNode findAllOperById(@PathVariable int id,HttpServletRequest request){
	    String tsrIdStr=request.getParameter("tsrId");
	    Integer tsrId=null;
	    if(StringUtil.isNotEmpty(tsrIdStr)){
	        tsrId=Integer.valueOf(tsrIdStr);
	    }
	    CheckTreeNode checkTreeNode=moduleService.findModuleByRoleId(id,tsrId);
	    return checkTreeNode;
    }
}
